//
//  SEPrimitives.cpp
//  Space Explorer
//
//  Created by Yann Blaudin de Thé on 19/04/13.
//  Copyright (c) 2013 TeaTime. All rights reserved.
//

#include "SEPrimitives.h"


void drawArrow(irr::IrrlichtDevice *device, const irr::core::vector3df& start, const irr::core::vector3df& end) {
    irr::video::IVideoDriver *driver = device->getVideoDriver();
    irr::scene::ICameraSceneNode *cam = device->getSceneManager()->getActiveCamera();
    
    irr::core::vector3df p1, p2;
    
    p1 = (end-start).crossProduct(cam->getTarget());
    p1.normalize();
    
    p2 = (end-start).crossProduct(p1);
    p2.normalize();
    
    irr::f32 lon = (start-end).getLength()/10.0f;
    
    driver->draw3DTriangle(irr::core::triangle3df(end,start+p1*lon,start-p1*lon));
    driver->draw3DTriangle(irr::core::triangle3df(end,start+p2*lon,start-p2*lon));
    
}

void drawFrame(irr::IrrlichtDevice *device, const irr::core::vector3df& center, const irr::core::matrix4& mat, irr::f32 radius) {
    irr::core::vector3df vec;
    
    vec = irr::core::vector3df(1,0,0);
//    mat.inverseRotateVect(vec);
    drawArrow(device, center, center+radius*vec);
    
    vec = irr::core::vector3df(0,1,0);
//    mat.inverseRotateVect(vec);
    drawArrow(device, center, center+radius*vec);
    
    vec = irr::core::vector3df(0,0,1);
//    mat.inverseRotateVect(vec);
    drawArrow(device, center, center+radius*vec);
    
}

